<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <style>
        .menudiv .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 450px !important;
            margin-right: 10px;
        }
        .buttondiv{
            display: none;
        }

    </style>
</head>
<body >
<div class="layui-fluid" id="flowDiv" >
        <div class="zTreeBackground left" style="float: left;width:250px">
        <div class="titlediv">
            <p style="text-align:right;background-color:white;line-height: 30px">
                专业领域信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="searchByName()"></i>&ensp;&ensp;
            </p>

        </div>
        <div class="searchdiv" >
            <div class="layui-input-inline" style="width:100%">
                <input type="text" id="search" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="searchByName()"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv" style="overflow:auto">
            <ul id="treeStructure" class="ztree"></ul>
        </div>
    </div>
    <div class="zTreeBackground right" style="float: left;width:65%; padding-left:1%">
        <!--<div>
            <button type="button" style="margin-left: 15px" class="layui-btn layui-btn-normal" onclick="add()"><i class="layui-icon">&#xe608;</i>添加</button>
            <button type="button" class="layui-btn layui-btn-normal" onclick="edit()"><i class="layui-icon">&#xe608;</i>编辑</button>
            <button type="button" class="layui-btn layui-btn-normal" onclick="del()"><i class="layui-icon">&#xe608;</i>删除</button>
        </div>-->
        <div class="menudiv">
            <div class="layui-card-body ">
                <table class="layui-table layui-form" id="datatable" lay-filter="data-table"></table>
                <script type="text/html" id="toolbar"></script>
            </div>

        </div>
    </div>
    <!--<div class="layui-row layui-col-space15">-->

        <!--<div class="layui-col-md4 treetool" id="flowDiv" onload="onLoad()">-->

        <!--</div>-->
        <!--<div class="layui-col-md8">-->
            <!--<input type="button" value="获取选中项" onclick="getSelectNode()"/>-->
            <!--<input type="button" value="获取check项" onclick="getCheckNode()"/>-->
            <!--<input type="button" value="刷新选中项" onclick="refreshSelectNode()"/>-->
        <!--</div>-->
    <!--</div>-->
</div>
</body>
<SCRIPT type="text/javascript">
    window.onload = getContentSize;
    window.onresize = getContentSize;
    var zTreeObj,form,table,pid=-1,pName="专业领域",type=1;//类型  1-领域 2-专业;

    layui.use(['form', 'layer'], function() {
        form = layui.form;
        layer = layui.layer;
        table = layui.table;


    });
    $(document).ready(function(){
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        loadTree();

        //单击行勾选checkbox事件
        $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
            var index = $(this).attr('data-index');
            var tableBox = $(this).parents('.layui-table-box');
            //存在固定列
            if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
                tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
            } else {
                tableDiv = tableBox.find(".layui-table-body.layui-table-main");
            }
            var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox i");
            if (checkCell.length>0) {
                checkCell.click();
            }
        });

        $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
            e.stopPropagation();
        });
        
    });


    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理
    }

    /* *
     * @Author bxf
     * @Description 重载table
     * @Date 8:40 2019/8/23
     * @param null
     * @return
     */
    function reload(){
        table.reload(id,null);
    }

    /**
     * 左侧树设置
     * @type {{check: {enable: boolean}, data: {simpleData: {enable: boolean, idKey: string, pIdKey: string, isParent: string, rootPid: number}}, callback: {beforeClick: zTreeBeforeClick, onClick: zTreeOnClick}}}
     */
    var setting = {
        check: {
            //enable: true
        },
        edit:{
            enable: false,
        },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"pid",
                isParent:"parent",
                rootPid:-1
            },
            key: {
                url: "xUrl",
                icon:"xIcon"
            }
        },
        callback: {
            // beforeClick: zTreeBeforeClick,
            onClick: zTreeOnClick
        }
    };



    /**
     * 点击触发
     * @param event
     * @param treeId
     * @param treeNode
     */
    function zTreeOnClick(event, treeId, treeNode) {
        //根据树的点击确定是专业还是领域
        if(treeNode.id==-1){
            type=1;
        }else {
            type=2;
        }
        //根据树的点击确定父级id、name
        pid=treeNode.id;
        pName=treeNode.name;
        loadTable();
    };

    //加载右边表格
    function loadTable(){
        var width = $(".left-nav").css("width");
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理

        layui.use(['laydate','form','table'], function(){
            var laydate = layui.laydate;
            table = layui.table;
            table.render({
                elem: '#datatable',
                size: 'sm',
                method: 'post',
                toolbar: '#toolbar',
                headers: {"Authorization":getData("Authorization")},
                height: 'full-50',
                url: publicUrl+'infDisciplines/selectAllDisciplines', //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                request: {
                    limitName: 'pageSize',
                    pageName: "pageIndex",
                },
                response: {
                    statusCode: 2000,
                },where:{
                    pid : pid,
                    type: type
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                }
                ,cols: [[
                    {
                        type: 'checkbox',
                        title: '',
                        width: "160px",
                        align: 'center'
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        width: "160px",
                        align: 'center'
                    },
                    {
                        field: 'name',
                        title: '名称',
                        width: "25%",
                        align: 'center'
                    },
                    {
                        field: 'fid',
                        title: 'IFD编码',
                        width: "25%",
                        align: 'center'
                    },
                    {
                        field: 'sort',
                        title: '排序',
                        width: "10%",
                        align: 'center'
                    },
                    {
                        field: 'comment',
                        title: '备注',
						width: "34%",
                        align: 'center'
                    }
                ]],
                page: true
            });
            // //监听行双击事件
             table.on('rowDouble(data-table)', function(obj){
                 show(obj);
             });
        });


    }




    /**
     * 模糊查询
     */
    function query(){
        loadTree($("#keyword").val());
    }

    /**
     * 加载左侧树
     */
    function loadTree(keyWord){
        publicAjax (null,'infDisciplines/selectAllDisciplinesByTree',{name: keyWord,type: 1},null,null,function (r) {
            var jsondata = r.data;
            var json = {"id":-1,"name":"专业领域", open:true};
            jsondata.push(json);
            zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, jsondata);
            var node = zTreeObj.getNodeByParam('id', -1);//获取id为1的点
            zTreeObj.selectNode(node);//选择点
            zTreeObj.setting.callback.onClick(null, zTreeObj.setting.treeId, node);//调用事件
        })
    }


    //新增
    function add(callback){
        var url='./addInfdisciplines.html?type='+type+"&pid="+pid+"&pName="+pName;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero);
                if(result.code==2000){
                    laysuccess("新增成功");
                }else{
                    layerror("新增失败");
                }
                layer.close(index);
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }
            }
        }
        layer.open({
            type: 2,
            area: [630 + 'px', 550 + 'px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "新增",
            content: url,
            btn: ['应用', '完成','关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero,'applye');
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }
                return false;
            },
            btn2:callback,
            cancel: function(index) {
                return true;
            }
        });
    }

    //刷新表格，必须要有参数提交，否则会不刷新
    function reloadTable(){
        table.reload('datatable', {
            where:{
                a:1
            }
        });
    }


    //显示详情
    function show(obj,callback){
        var url='./editinfdisciplines.html?id='+obj.data.id+"&pName="+pName;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submit(index, layero);
                layer.close(index);
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }

            }
        }
        layer.open({
            type: 2,
            area: [630 + 'px', 550 + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "查看",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            cancel: function(index) {
                return true;
            }
        });
    }


    //批量删除
    function del(){
        var checks= table.checkStatus('datatable');
        if(checks.data.length==0){
            layer.alert('请选中一行数据');
            return;
        }
        var ids=[];
        for(var i=0;i<checks.data.length;i++){
            ids[i]=checks.data[i].id;
        }
        layer.confirm('你确认删除么?', {icon: 3, title:'提示'}, function(index){
            layer.close(index);
            publicAjax (null,'infDisciplines/deleteInfDisciplines',{ids: ids,type : type},null,null,function (r) {
                if(r.code==2000){
                    laysuccess("删除成功");
                }else{
                    layerror(r.msg);
                }
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }
            })
        });
    }




    //修改
    function edit(callback){
        var checks= table.checkStatus('datatable');
        if(checks.data.length!=1){
            layer.alert('请选中一行数据');
            return;
        }
        var url='./editinfdisciplines.html?id='+checks.data[0].id+"&pName="+pName;
        if(isEmpty(callback)){
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero);
                if(result.code==2000){
                    laysuccess("修改成功");
                }else{
                    layerror("修改失败");
                }
                layer.close(index);
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }
            }
        }
        layer.open({
            type: 2,
            area: [630 + 'px', 550 + 'px'],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "编辑",
            content: url,
            btn: ['确定','应用', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: callback,
            btn2:function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                var result=iframeWin.contentWindow.submit(index, layero,'applye');
                if(type==1){
                    loadTree();
                }else{
                    reloadTable();
                }
                return false;
            },
            cancel: function(index) {
                return true;
            }
        });
    }



    function isEmpty(value) {
        if (value == null || this.trim(value) == "") {
            return true;
        }
        return false;
    }



</SCRIPT>
</html>